<template>
  <div>
   <Row>
      <Card>
        <Form ref="search" :model="searchData" :rules="searchReg" :label-width="80">
          <!--<Row>-->
            <!--<i-col :xs="24" :md="12" :lg="6">-->
              <!--<FormItem label="搜索部门" prop="name">-->
                <!--<Input-->
                        <!--v-model="searchData.department"-->
                        <!--suffix="ios-search"-->
                        <!--placeholder="请输入部门名称"-->
                        <!--style="width: auto"-->
                <!--&gt;-->
                  <!--<Icon type="ios-search" slot="suffix"/>-->
                <!--</Input>-->
              <!--</FormItem>-->
            <!--</i-col>-->
          <!--</Row>-->
          <Row>
            <i-col :xs="24" :md="12" :lg="6">
              <FormItem label="年份">
                <DatePicker
                        type="year"
                        format="yyyy"
                        @on-change="searchSelectYear"
                        placeholder="按年份搜索"
                        style="width:185px"
                        v-model="searchData.dateTime"
                ></DatePicker>
              </FormItem>
            </i-col>
          </Row>
          <FormItem>
            <Button
                    type="primary"
                    style="marigin:0 20px"
                    :loading="searchLoading"
                    @click="searchSubmit(10,1)"
            >提交搜索</Button>
            <Button @click="submitReset">重置搜索</Button>
          </FormItem>
        </Form>
      </Card>
    </Row>
    <Row style="margin-top:20px">
      <Card>
        <Table
                border
                highlight-row
                :loading="tabelLoading"
                ref="currentRowTable"
                :columns="workDataTitle"
                :data="workDataContent1"
                :height="700"
        ></Table>
        <div style="margin-top:20px;margin-left:35%">
          <Page
                  @on-change="pageNumberChange"
                  :page-size="pageSize"
                  :total="pageTotal"
                  @on-page-size-change="pageSizeChange"
                  show-elevator
                  show-sizer
          />
        </div>
      </Card>
    </Row>
  </div>
</template>
<script>
import { hasOneOf } from "@/libs/tools";
import { workAjax } from "@/api/city";
// 查询URL
const QUERY_URL = "/workScore/query";
// 修改URL
const UPDATE_URL = "/workScore/update";
// 添加URL
const INSERT_URL = "/workScore/insert";
export default {
  data() {
    return {
      modalTitle: "", // 模态框title
      submitloading: false, // 提交loading
      searchLoading: false, // 搜索loading
      tabelLoading: false,
      isInsertModal: false, // 模态框
      pageSize: 20, // 10
      pageNumber: 1,
      pageTotal: 20, // 10
      searchData: {
        department: "", // 部门
        dateTime: "" // 年份
      },
      isDisabledSubmit: false,
      workForm: {
        cityResponUnit: "", // 责任单位
        time: "", // 时间
        comprehensive: "", // 部门综合评分
        department: "", // 部门
        dateTime: "", // 年份
        monthTime: "", // 月份
        score: null, // 分数
        maxPoint: null, // 分数上线
        reason: "" // 回退原因
      },
      searchReg: {},
      workFormReg: {
        department: [
          {
            required: true,
            message: "请输入部门名称",
            trigger: "blur"
          }
        ]
      },
      workDataTitle: [
        {
          type: "index",
          width: 60,
          align: "center"
        },
        {
          title: "部门",
          key: "department"
        },
        {
          title: "领导评分",
          key: "leader"
        },
        {
          title: "其他部门负责人评分",
          key: "other"
        },
        {
          title: "部门综合评分",
          key: "comprehensive"
        },
        {
          title: "时间",
          key: "time"
        }
      ],
      workDataContent1: [],
      workDataContent: [
        {
          department: "党政办",
          leader: 97.636,
          other: 99.053,
          comprehensive: 98.0611,
          time: "2018年"
        },
        {
          department: "财政金融局",
          leader: 97.273,
          other: 98.737,
          comprehensive: 97.7122,
          time: "2018年"
        },
        {
          department: "监察审计局",
          leader: 97,
          other: 98.684,
          comprehensive: 97.5052,
          time: "2018年"
        },
        {
          department: "党群工作部",
          leader: 96.818,
          other: 98.789,
          comprehensive: 97.4093,
          time: "2018年"
        },
        {
          department: "公安分局",
          leader: 96.818,
          other: 98.421,
          comprehensive: 97.2989,
          time: "2018年"
        },
        {
          department: "“智慧高新区”管理服务中心",
          leader: 96.727,
          other: 98.474,
          comprehensive: 97.2511,
          time: "2018年"
        },
        {
          department: "商务局",
          leader: 96.727,
          other: 98.368,
          comprehensive: 97.2193,
          time: "2018年"
        },
        {
          department: "交警大队",
          leader: 96.636,
          other: 98.368,
          comprehensive: 97.1556,
          time: "2018年"
        },
        {
          department: "综合执法局",
          leader: 96.545,
          other: 998.368,
          comprehensive: 97.0919,
          time: "2018年"
        },
        {
          department: "经济发展局",
          leader: 96,
          other: 98.105,
          comprehensive: 96.6315,
          time: "2018年"
        },
        {
          department: "税务局",
          leader: 95.727,
          other: 98.526,
          comprehensive: 96.5667,
          time: "2018年"
        },
        {
          department: "综治信访中心",
          leader: 95.455,
          other: 98.526,
          comprehensive: 96.3763,
          time: "2018年"
        },
        {
          department: "市场监督管理局",
          leader: 95.364,
          other: 98.421,
          comprehensive: 96.2811,
          time: "2018年"
        },
        {
          department: "村镇办",
          leader: 95.364,
          other: 98.211,
          comprehensive: 96.2181,
          time: "2018年"
        },
        {
          department: "行政审批局",
          leader: 95.091,
          other: 98.526,
          comprehensive: 96.1215,
          time: "2018年"
        },
        {
          department: "国土环保局",
          leader: 95.364,
          other: 98.158,
          comprehensive: 96.0748,
          time: "2018年"
        },
        {
          department: "社会事业管理局",
          leader: 95,
          other: 98.263,
          comprehensive: 95.9789,
          time: "2018年"
        },
        {
          department: "规划建设局",
          leader: 94.818,
          other: 98.421,
          comprehensive: 95.8989,
          time: "2018年"
        },
        {
          department: "南屿镇",
          leader: 94.727,
          other: 98.211,
          comprehensive: 95.7722,
          time: "2018年"
        },
        {
          department: "供电服务中",
          leader: 93.182,
          other: 98.105,
          comprehensive: 94.6589,
          time: "2018年"
        }
      ]
    };
  },
  methods: {
    showState() {
      this.$refs["work"].resetFields();
    },
    // 重置搜索内容
    submitReset() {
      this.searchData = {
        department: "", // 部门
        dateTime: "" // 年份
      };
      this.searchLoading = false;
    },
    // 搜索提交
    searchSubmit(pageSize, pageNumber) {
      this.pageSize = pageSize;
      this.pageNumber = pageNumber;
      this.searchLoading = true;
      this._getWorkeData(
        this.searchData,
        QUERY_URL,
        this.pageSize,
        this.pageNumber
      );
    },
    // 关闭模态框
    closeModal() {
      this.isInsertModal = false;
    },
    // 删除工作督查指标
    workRemove(index) {},
    // 搜索年份时间转换
    searchSelectYear(year) {
      this.searchData.dateTime = year;
    },
    // 工作督查指标年份
    workSelectYear(year) {
      this.workForm.dateTime = year;
    },
    // 页码
    pageNumberChange(pageNumber) {
      this.pageNumber = pageNumber;
      this._getWorkeData(
        this.searchData,
        QUERY_URL,
        this.pageSize,
        this.pageNumber
      );
    },
    // 页数
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this._getWorkeData(
        this.searchData,
        QUERY_URL,
        this.pageSize,
        this.pageNumber
      );
    },
    // 添加编辑AJAX
    // _workAjax(url, formData) {
    //   const keyOne = "workScoreEntity";
    //   return new Promise((resolve, reject) => {
    //     workAjax({ url, formData, keyOne })
    //       .then(result => {
    //         if (result.data !== undefined) {
    //           resolve(result.data);
    //         } else {
    //           reject(err);
    //         }
    //       })
    //       .catch(err => {
    //         console.log(err);
    //       });
    //   });
    // },
    // 获取新闻,列表数据
    _getWorkeData(formData, url, pageSize, pageNumber) {
      this.tabelLoading = true;
      formData = Object.assign(formData, {
        pageSize,
        pageNumber
      });
      const keyOne = "workScoreFilter";
      workAjax({ formData, url, keyOne })
        .then(result => {
          this.tabelLoading = false;
          if (result.data.code === "200") {
            this.searchLoading = false;
            // this.workDataContent = result.data.results.list;
            this.workDataContent1 = []
            if (formData.dateTime === '') {
              this.workDataContent1 = this.workDataContent
            } else {
              for (let i = 0; i < this.workDataContent.length; i++) {
                if (this.workDataContent[i].time === formData.dateTime + '年') {
                  this.workDataContent1.push(this.workDataContent[i])
                }
              }
            }
            this.pageTotal = parseInt(result.data.results.pageTotal) * 10;
            this.$Message.success("查询成功");
          } else {
            this.$Message.error("查询失败");
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  created() {
    this._getWorkeData(
      this.searchData,
      QUERY_URL,
      this.pageSize,
      this.pageNumber
    );
  },
  computed: {
    getDepartmentList() {
      return this.$store.state.user.departmentList;
    },
    access() {
      return this.$store.state.user.access;
    },
    // 管理员
    accessAdmin() {
      return hasOneOf(["admin"], this.access);
    },
    // 责任人
    accessRespons() {
      return hasOneOf(["responsible"], this.access);
    },
    // 经办人
    accessAgent() {
      return hasOneOf(["agent"], this.access);
    }
    //
  }
};
</script>
<style>
  .ivu-input[disabled],
  fieldset[disabled] .ivu-input {
    color: #333;
  }
  .ivu-input-number-input[disabled] {
    color: #333;
  }
</style>
